module.exports = class Queue {
    // 队列容器
    #items = {}
    // 队列头指针
    #headPointer = 0
    // 队列尾指针
    #endPointer = 0

    // 入队
    enQueue(data) {
        // 队尾入队
        this.#items[this.#endPointer] = data
        // 队尾指针后移
        this.#endPointer++
    }

    // 出队
    deQueue() {
        let res = this.#items[this.#headPointer]
        // 队首出队（直接删除队首元素）
        delete this.#items[this.#headPointer]
        // 队首指针后移
        this.#headPointer++
        // 返回出队元素
        return res
    }

    // 清栈
    clear() {
        this.#items = {}
        this.#headPointer
    }

    // 队列当前规模
    size() {
        return this.#endPointer - this.#headPointer
    }

    // 是否是空队列
    isEmpty() {
        return this.size() === 0
    }

    toString() {
        let str = ''
        for (let i = this.#headPointer; i < this.#endPointer; i++) {
            str += `${this.#items[i]} `
        }
        return str
    }
}